package com.liao.ticket.util;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 *  vip政策：用户里程数达到要求，可享受对应优惠
 * 1.黄金vip
 *   里程数 > 10000 , 优惠 0.98
 * 2.白金vip
 *   里程数 > 20000 , 优惠 0.95 , 5kg托运
 * 3.钻石vip
 *   里程数 > 100000 , 优惠 0.90 ， 10kg托运
 */
public class PreferentialUtils {
    private static DecimalFormat format = new DecimalFormat("0.00");

    private static final Integer mileage1 = 10000;

    private static final Integer mileage2 = 20000;

    private static final Integer mileage3 = 100000;

    private static final BigDecimal discount1 = new BigDecimal(0.98);

    private static final BigDecimal discount2 = new BigDecimal(0.95);

    private static final BigDecimal discount3 = new BigDecimal(0.90);

    public static BigDecimal getPrice(Integer mileage,BigDecimal price){
        if(mileage > 100000){
            price = price.multiply(discount2);
        }else if(mileage > 20000){
            price = price.multiply(discount2);
        } else if (mileage > 10000) {
            price = price.multiply(discount1);
        }
        return formatPrice(price);
    }

    public static BigDecimal formatPrice(BigDecimal price){
        return new BigDecimal(format.format(price));
    }

    public static void main(String[] args) {
        BigDecimal bigDecimal = new BigDecimal(109);
        Long star = System.currentTimeMillis();
        System.out.println(getPrice(23000, bigDecimal));
        System.out.println(System.currentTimeMillis() - star);
    }
}
